package com.tutk.P2PCam264;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import com.tutk.agza.NotifyInfo;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;

/**
 * Created by huanlinchen on 14/12/2015.
 */
public class DownloadWebPicture {

    public void getURLimg(final String imgUrl , final NotifyInfo notifyInfo , final Context ctx) {

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        Bitmap bitmap;
                        ctx.getApplicationContext();

                        try {
                            URL url = new URL(imgUrl);
                            URLConnection conn = url.openConnection();

                            HttpURLConnection httpConn = (HttpURLConnection) conn;
                            httpConn.connect();

                            if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                                InputStream inputStream = httpConn.getInputStream();
                                bitmap = BitmapFactory.decodeStream(inputStream);
                                Log.d("TPNS", "Bmp " + bitmap.getWidth() + "x" + bitmap.getHeight());
                                AgzaReceiver.getBitmapReceiveNotify(bitmap, notifyInfo, ctx);
                                inputStream.close();
                            }
                        } catch (MalformedURLException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();

    }
}

